import { ref } from 'vue'
import { getDepList, getGradeList } from '@/api/user'

// 全局的学院与年级选项（行为分析、消费记录页等均可复用）
export const departments = ref([])
export const grades = ref([])

export async function ensureSchoolOptions() {
  if (departments.value.length && grades.value.length) return
  try {
    const [depRes, gradeRes] = await Promise.all([getDepList(), getGradeList()])
    if (depRes?.code === 1 && Array.isArray(depRes.data)) {
      departments.value = depRes.data
    }
    if (gradeRes?.code === 1 && Array.isArray(gradeRes.data)) {
      grades.value = gradeRes.data
    }
  } catch (e) {
    // 静默失败
  }
}